package com.baiyue.result;

/**
 * 状态码，错误码
 * @author liuyanzhao
 */
public class CodeMsg {

    private int code;
    private String msg;

    //通用的错误码
    public static CodeMsg SUCCESS = new CodeMsg(200, "成功");
    public static CodeMsg FAILURE = new CodeMsg(201, "失败");

    public static CodeMsg SERVER_ERROR = new CodeMsg(5001, "服务端异常");
    public static CodeMsg DATABASE_ERROR = new CodeMsg(5001, "数据库更新异常");
    public static CodeMsg BIND_ERROR = new CodeMsg(5001, "参数校验异常：%s");
    public static CodeMsg REQUEST_ILLEGAL = new CodeMsg(5001, "非法请求");
    public static CodeMsg ACCESS_LIMIT_REACHED = new CodeMsg(5001, "访问太频繁！");
    public static CodeMsg FILE_TYPE_ERROR = new CodeMsg(5001, "文件格式不支持！");
    public static CodeMsg FILE_READ_ERRIR = new CodeMsg(5001, "文件读取失败！");


    public static CodeMsg USER_NOT_LOGIN = new CodeMsg(5002, "用户未登录");
    public static CodeMsg TOKEN_INVALID = new CodeMsg(5002, "token无效");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(5002, "密码错误");
    public static CodeMsg COOKIE_IS_NOT_LOGIN = new CodeMsg(5002,"登录token验证无效，请重新登录");


    public static CodeMsg USERNAME_ALREADY_EXISTS = new CodeMsg(5003,"用户已存在");
    public static CodeMsg ALREADY_EXISTS = new CodeMsg(5003,"%s 已存在");
    public static CodeMsg TABLE_CHARGING_CLOSE = new CodeMsg(5003, "该订单已结束，请刷新！");

    public static CodeMsg USERNAME_NOT_EXIST = new CodeMsg(5004, "用户名不存在");
    public static CodeMsg TOLL_NOT_EXIST = new CodeMsg(5004, "计费规则不存在");
    public static CodeMsg TABLE_CHARGING_EXIST = new CodeMsg(5004, "包间开单信息不存在");

    public static CodeMsg MENU_NOT_EXIST = new CodeMsg(5005, "菜单不存在");

    public CodeMsg() {
    }

    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public CodeMsg fillArgs(Object... args) {
        int code = this.code;
        String message = String.format(this.msg, args);
        return new CodeMsg(code, message);
    }

    @Override
    public String toString() {
        return "CodeMsg [code=" + code + ", msg=" + msg + "]";
    }


}
